//
//  WWKTableViewController.m
//  WWK个人中心
//
//  Created by 王文景 on 16/7/4.
//  Copyright © 2016年 wwj. All rights reserved.
//
//https://api.weibo.com/2/users/show.json?access_token=2.00Es_OWFd4DcPDa6dc00e2564wXHAD&uid=5056919892
#import "WWKTableViewController.h"

#import "MYModel.h"

#import "WWKTableViewCell.h"

#import "MJExtension.h"

#import "UIView+Frame.h"
#import <AFNetworking.h>
#import "WWKAddFriends.h"
#import "WWKSettings.h"
#import "WeiboLogin.h"
#import "GetWeiboAccount.h"
#import "WBAccount.h"

#import "WWKUserModel.h"
#import "WWKUserView.h"

@interface WWKTableViewController ()

@property (nonatomic, strong) NSMutableArray *friends;
@property (nonatomic, strong) NSMutableArray *group;
@property (weak, nonatomic) IBOutlet WWKUserView *userView;
@end

@implementation WWKTableViewController

- (NSMutableArray *)group {
    if (!_group) {
        _group = [NSMutableArray array];
        NSArray *dictArray = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Profile.plist" ofType:nil] ];
        for (NSArray *arr in dictArray) {
            
            [_group addObject:[MYModel mj_objectArrayWithKeyValuesArray:arr]];
        }

    }
    return _group;
}

//-(NSMutableArray *)friends {
//    if (_friends == nil) {
//        
//    }
//    return _friends ;
//}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
    
    self.tableView.sectionFooterHeight = 5;
    self.tableView.sectionHeaderHeight = 5;
    
    
    
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    [self requestUserInfo];
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    NSLog(@"%ld",self.group.count);
    return self.group.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    NSArray *arr = self.group[section];
    NSLog(@"%@",arr);
    return arr.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *ID = @"My";
    WWKTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    
    cell.My = self.group[indexPath.section][indexPath.row];
    
    return cell;
   
    
}

#pragma mark - UITabeleViewDelegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section == 0 && indexPath.row == 0) {
        
        UIViewController *vc = [UIViewController new];
        vc.view.backgroundColor = [UIColor redColor];
        [self.navigationController pushViewController:vc animated:YES];
        
    }else if(indexPath.section == 0 && indexPath.row == 1) {
        
        UIViewController *vc = [UIViewController new];
        vc.view.backgroundColor = [UIColor redColor];
        [self.navigationController pushViewController:vc animated:YES];
    }else if(indexPath.section == 1 && indexPath.row == 0) {
        
        UIViewController *vc = [UIViewController new];
        vc.view.backgroundColor = [UIColor redColor];
        [self.navigationController pushViewController:vc animated:YES];
    }else if(indexPath.section == 1 && indexPath.row == 1) {
        
        UIViewController *vc = [UIViewController new];
        vc.view.backgroundColor = [UIColor redColor];
        [self.navigationController pushViewController:vc animated:YES];
    }else if(indexPath.section == 1 && indexPath.row == 3) {
        
        UIViewController *vc = [UIViewController new];
        vc.view.backgroundColor = [UIColor redColor];
        [self.navigationController pushViewController:vc animated:YES];
    }else if(indexPath.section == 2 && indexPath.row == 0) {
        
        UIViewController *vc = [UIViewController new];
        vc.view.backgroundColor = [UIColor redColor];
        [self.navigationController pushViewController:vc animated:YES];
    }else if(indexPath.section == 2 && indexPath.row == 1) {
        
        UIViewController *vc = [UIViewController new];
        vc.view.backgroundColor = [UIColor redColor];
        [self.navigationController pushViewController:vc animated:YES];
    }else if(indexPath.section == 3 && indexPath.row ==0 ) {
        
        UIViewController *vc = [UIViewController new];
        vc.view.backgroundColor = [UIColor redColor];
        [self.navigationController pushViewController:vc animated:YES];
    }else if(indexPath.section == 4 && indexPath.row == 0) {
        
        UIViewController *vc = [UIViewController new];
        vc.view.backgroundColor = [UIColor redColor];
        [self.navigationController pushViewController:vc animated:YES];
    }else if(indexPath.section == 5 && indexPath.row == 0) {
        
        UIViewController *vc = [UIViewController new];
        vc.view.backgroundColor = [UIColor redColor];
        [self.navigationController pushViewController:vc animated:YES];
    }
}
//添加好友
- (IBAction)addFriends:(id)sender {
    
//    WWKAddFriends *vc = [WWKAddFriends new];
    UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"WWKAddFriends" bundle:nil];
    
    
    //加载StoryBoard当中指定名称的控制器
    WWKAddFriends *vc = [storyBoard instantiateViewControllerWithIdentifier:@"redVC"];
       
    [self.navigationController pushViewController:vc animated:YES];
//
//    [[UIApplication sharedApplication].keyWindow.rootViewController  presentViewController:vc animated:YES completion:nil];
  
    
}

// 设置
- (IBAction)Settings:(id)sender {
    UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"WWKSettings" bundle:nil];
    
    //加载StoryBoard当中指定名称的控制器
    WWKSettings *vc1 = [storyBoard instantiateViewControllerWithIdentifier:@"Settings"];
    
    [self.navigationController pushViewController:vc1 animated:YES];
}



- (void)requestUserInfo {
    //    ?access_token=2.00Es_OWFd4DcPDa6dc00e2564wXHAD&uid=5056919892
    WBAccount *account = [GetWeiboAccount getAccount];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"access_token"] = account.wbToken;
    params[@"uid"] = account.wbCurrentID;
    
    //
    /**
     screen_name  用户名
     profile_image_url	string	用户头像地址（中图），50×50像素
     description        string	用户个人描述
     followers_count	int	粉丝数
     friends_count      int	关注数
     statuses_count     int	微博数
     
     */
    
    
    
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    [manager GET:@"https://api.weibo.com/2/users/show.json" parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        NSLog(@"---------%@",responseObject);
        
        
        // 给UserView传递模型
        self.userView.datum = [WWKUserModel mj_objectWithKeyValues:responseObject];
        
        [self.tableView reloadData];
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        
        NSLog(@"%@",error);
        
    }];
    
    
    
    
    
}

@end
